<?php
namespace Swiftx\Component\Router\Dispatcher;
use Swiftx\Component\Router\Dispatcher;
use Swiftx\Interfaces\Router\Request;
use Swiftx\Interfaces\Router\Response;

/**
 * 路由分发器
 *
 * @author		胡永强  <odaytudio@gmail.com>
 * @since		2015-10-09
 * @copyright	Copyright (c) 2014-2015 Swiftx Inc.
 */
class Callback extends Dispatcher {

    /**
     * 回调方法
     * @var callable
     */
    protected $action;

    /**
     * 设置请求回调
     * @param callable $foo
     */
    public function setFunction(callable $foo){
        $this->action = $foo;
    }

    /**
     * 获取相应
     * @param Request $request
     * @param Response $response
     * @return void
     */
    public function bundle(Request $request, Response $response) {
        $this->parseParams($request);
        if(call_user_func($this->action, $request, $response))
            $request->setStatus($request::Success);
        else $request->setStatus($request::Error);
    }

}